package com.example.mr5.money.main.myincome.addincome;/**
 * Created by Mr.5
 * Date：2016/9/13.
 * Time：22:34
 */

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.mr5.money.R;
import com.example.mr5.money.model.CommonType;

import java.util.List;

/**
 * Created by Mr.5 
 * Date：2016/9/13.
 * Time：22:34
 */
public class FirstListAdapter extends BaseAdapter {

    private Context context;
    private List<CommonType> commonTypeList;
    private int clickItem = 0;

    public FirstListAdapter(Context context, List<CommonType> commonTypeList){
        this.context = context;
        this.commonTypeList = commonTypeList;
    }

    @Override
    public int getCount() {
        return commonTypeList.size();
    }

    @Override
    public CommonType getItem(int position) {
        return commonTypeList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null){
            holder = new Holder();
            convertView = View.inflate(context,R.layout.item_common_type_list,null);
            holder.name = (TextView) convertView.findViewById(R.id.type_name);
            holder.arrow = (ImageView) convertView.findViewById(R.id.arrow);
            convertView.setTag(holder);
        }else {
            holder = (Holder) convertView.getTag();
        }
        holder.name.setText(commonTypeList.get(position).getName());
        holder.arrow.setVisibility(View.VISIBLE);
        if (clickItem != position) {
            convertView.setBackgroundColor(context.getResources().getColor(R.color.money_white));
        }else {
            convertView.setBackgroundColor(context.getResources().getColor(R.color.money_gray_list));
        }

        return convertView;
    }

    public void setSelection(int position) {
        this.clickItem = position;
    }

    private class Holder{
        private TextView name;
        private ImageView arrow;
    }
}
